<template>
  <!-- 批量修改任务状态对话框 -->
  <el-dialog append-to-body :title="title" :visible.sync="visible" width="600px">
    <el-form ref="form" :model="model" :rules="rules" label-width="120px" class="dialog-form">
      <el-row>
        <!-- <el-col :span="colSpan">
          <el-form-item label="验收任务状态">
            <el-select v-model="model.taskStatus" placeholder="请选择任务状态">
              <el-option
                v-for="dict in taskStatusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="colSpan" v-if="!parent">
          <el-form-item label="企业" prop="distDeptId">
            <treeselect v-model="model.distDeptId" :options="deptOptions" placeholder="选择企业" />
          </el-form-item>
        </el-col>
        <el-col :span="colSpan">
          <el-form-item label="标注工厂">
            <el-select v-model="model.factoryIds" multiple placeholder="请分配标注工厂" :disabled="workStarted">
              <el-option
                v-for="item in factoriesOptions"
                :key="item.id"
                :label="item.label"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="colSpan">
          <el-form-item label="标注类型">
            <el-select v-model="model.markType" placeholder="请选择标注类型" :disabled="workStarted">
              <el-option
                v-for="dict in markTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="colSpan">
          <el-form-item label="标注属性字典" prop="markAttributes" :disabled="workStarted">
            <el-input v-model="model.markAttributes" placeholder="请输入已配置的标注属性字典名称" />
          </el-form-item>
        </el-col>
        <el-col :span="colSpan">
          <el-form-item label="应用到子任务" prop="applySubtask">
            <el-switch
              v-model="model.applySubtask"
              :active-value="true"
              active-text="是"
              :inactive-value="false"
              inactive-text="否"
            ></el-switch>
            <!-- <el-checkbox v-model="model.applySubtask" placeholder="修改的字段应用到子任务" /> -->
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
      <el-button @click="handleCancle">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import Treeselect from '@riophae/vue-treeselect'

import {
  listQaTask,
  listQaTaskChecker,
  listQaTaskQa,
  getQaTask,
  getTaskWithParent,
  updateQaTaskStatus,
  delQaTask,
  addQaTask,
  updateQaTask,
  summarize,
  batchSummarize,
  taskAutoCheck,
} from '@/api/mark/qaTaskV1'
export default {
  name: 'TaskBatchDialog',
  components: { Treeselect },

  props: {
    parent: { type: Object, default: null },

    taskStatusOptions: { type: Array },
    deptOptions: { type: Array },
    factoriesOptions: { type: Array },
    markTypeOptions: { type: Array },
  },

  data() {
    return {
      title: '批量修改任务',
      visible: false,

      colSpan: 24,

      model: {
        taskStatus: undefined,
        distDeptId: undefined,
        factoryIds: undefined,
        markType: undefined,
        markAttributes: undefined,
        applySubtask: false,
      },

      rules: {},
    }
  },

  computed: {
    workStarted() {
      return this.parent && this.parent.status >= 30
    },
    workDone() {
      return this.parent && this.parent.status >= 90
    },
  },
  methods: {
    open() {
      this.visible = true
    },
    close() {
      this.visible = false
    },

    handleSubmit() {
      this.$confirm('请确实是否批量修改选中任务状态', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$emit('submit', { ...this.model })
        })
        .catch(function () {})
    },
    handleCancle() {
      this.visible = false
    },
  },
}
</script>

<style lang="scss" scoped>
.dialog-form {
  padding: 0 20px;
  .el-select {
    width: 100%;
  }
  .el-input-number {
    width: 100%;
  }
}
</style>
